package com.sgb.kjwl.view.ui.activity.leaseAsk.fragment;

import static android.app.Activity.RESULT_OK;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.sdk.mobile.manager.login.NoDoubleClickListener;
import com.sgb.capital.utils.DialogHelper;
import com.sgb.kjwl.R;
import com.sgb.kjwl.TitleImmerse;
import com.sgb.kjwl.databinding.FragmentAskLeaseHouse1Binding;
import com.sgb.kjwl.model.entity.PublishLeaseDataEntity;
import com.sgb.kjwl.model.entity.lease.AskLeaseItemEntity;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.model.entity.user.UnitEntity;
import com.sgb.kjwl.utils.EditInputFilter;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.viewmodel.machine.AskLeaseCommonModel;
import com.sgb.kjwl.viewmodel.machine.AskLeaseHouseModel2;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.util.SharedPreferenceUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class AskLeaseHouseFragment1 extends Fragment implements ItemInputTextView.OnWholeItemClickListener {

    private AskLeaseHouseModel2 viewModel;
    private AskLeaseCommonModel commonModel;
    private FragmentAskLeaseHouse1Binding binding;
    // 一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    // 二级联动数据
    private List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    // 三级联动数据
    private List<List<List<AddressEntity>>> opt3 = new ArrayList<>();
    private int cityPosition1, cityPosition2, cityPosition3;
    private Calendar selectedDate, selectedDate2;
    private List<PickSelectEntity> classDatas = new ArrayList<>();
    private List<List<PickSelectEntity>> typeDatas = new ArrayList<>();
    private List<UnitEntity> UnitDatas = new ArrayList<>();
    private List<PickSelectEntity> limitTimeDatas = new ArrayList<>();
    private List<DictEntity3> allpayway = new ArrayList<>();
    private List<PickSelectEntity> leaseTimeDatas = new ArrayList<>();//租赁时长单位


    private String lat;
    private String lon;
    private String id = "";
    private String secondCategoryName = "";
    private OptionsPickerView leaseTimeOpv;

    public void onAttach(Context context) {
        super.onAttach(context);
        id = getArguments().getString("id");
    }

    public static AskLeaseHouseFragment1 newInstance(String id) {
        AskLeaseHouseFragment1 frag = new AskLeaseHouseFragment1();
        Bundle bundle = new Bundle();
        bundle.putString("id", id);
        frag.setArguments(bundle);
        return frag;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_ask_lease_house_1, container, false);
        binding.setLifecycleOwner(this);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        viewModel = new ViewModelProvider(getActivity()).get(AskLeaseHouseModel2.class);
        commonModel = new ViewModelProvider(this).get(AskLeaseCommonModel.class);
        recevierliveData();
        initView();
        initData();
    }

    private void recevierliveData() {
        viewModel.showLoad.observe(getActivity(), aBoolean -> {
            if (aBoolean) {
                DialogHelper.showProgressDialog(getActivity(), "加载中...", 0, false).setCanceledOnTouchOutside(false);
            } else {
                DialogHelper.dismissProgressDialog();
            }
        });
        viewModel.msgLiveData.observe(getActivity(), data -> MToast.showToast(getActivity(), data));
        viewModel.showEditLiveData.observe(getActivity(), data -> showEdit(data));
        viewModel.showTypeViewLiveData.observe(getActivity(), it -> showTypeView(it));
        viewModel.initAddressDataLiveData.observe(getActivity(), it -> initAddressData(it));

        viewModel.getAllPayWayLiveData.observe(getActivity(), it -> getAllPayWay(it));
        commonModel.leaseTimeUnitLiveData.observe(getActivity(), t -> {
            leaseTimeDatas.addAll(t);
            showLeaseTime();
        });
    }

    private void initView() {
        binding.setViewModel(viewModel);
        //立即发布按钮
        binding.nextItem.btNextStep.setOnClickListener(v -> {
            if (checkInput()) {
                viewModel.selectFragLiveData.postValue(1);
            }
        });
        binding.nextItem.publicView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View view) {
                if (checkInput()) {
                    viewModel.getequimentLeasing(viewModel.entity);
                }
            }
        });
        binding.includeTime.tvTimeUnit.setOnClickListener(v -> {//租赁时长
            if (leaseTimeOpv != null) {
                leaseTimeOpv.show();
            }
        });
        binding.itvType.setOnWholeItemClickListener(this);
        binding.itvFloorStructure.setOnWholeItemClickListener(this);
        binding.address.setOnWholeItemClickListener(this);
        binding.timeCourse.setOnWholeItemClickListener(this);
        binding.timeDeadline.setOnWholeItemClickListener(this);
        binding.paymentMethod.setOnWholeItemClickListener(this);
        binding.address.setContentTextEnd();
        binding.itemTvPhone.setInputType(InputType.TYPE_CLASS_PHONE);
        binding.includeTime.leaseTime.setFilters(new EditInputFilter[]{new EditInputFilter(99999999, 1, 0)});
        binding.inLeasePrice.leasePrice.setFilters(new EditInputFilter[]{new EditInputFilter(99999999.99, 2)});
        binding.include.tvUse.setOnClickListener(v -> binding.include.itemTvTitleEdit.setEditContent(binding.include.tvTitleDefault.getText().toString()));
        binding.include.rlLeaseTitle.setVisibility(View.GONE);

        //   面议还是报价功能
        binding.inLeasePrice.rbPrice.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                binding.inLeasePrice.rbPrice.setButtonDrawable(R.mipmap.lease_pub_select);
                binding.inLeasePrice.layoutPrice.setVisibility(View.GONE);
                binding.inLeasePrice.rbPrice.setText("您已选择面议，再次点击退出面议");
            } else {
                binding.inLeasePrice.rbPrice.setButtonDrawable(R.mipmap.lease_pub_unselect);
                binding.inLeasePrice.layoutPrice.setVisibility(View.VISIBLE);
                binding.inLeasePrice.leasePrice.setText("");
                binding.inLeasePrice.leasePrice.setHint("请输入(必填)");
                binding.inLeasePrice.rbPrice.setText("面议");
            }
        });

        binding.houseArea.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
//                binding.houseArea.setText(s.toString());
                setDefaultTitle();
            }
        });
    }

    private void initData() {
        lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.SelectLATITUDE, "");
        lon = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.SelectLONGITUDE, "");
        String contact = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.REAL_NAME, "");
        String loginPhone = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_PHONE, "");
        binding.leaseUsername.setContent(contact);
        binding.itemTvPhone.setContent(loginPhone);

        selectedDate = Calendar.getInstance();
        selectedDate2 = Calendar.getInstance();
        viewModel.getAddressModel();//请求省市区数据
        viewModel.getTypeModel();//数据类型
        viewModel.getAllPayWay();//付款方式
        commonModel.getLeaseTimeUnit(3 + "");//获取租赁时长单位
        for (int i = 1; i < 30; i++) {
            PickSelectEntity timedentity = new PickSelectEntity();
            timedentity.setNo("" + i);
            timedentity.setProjectscale(i + "天");
            limitTimeDatas.add(timedentity);
        }

        if (!TextUtils.isEmpty(id)) {
            viewModel.getDeviceDetail(id, "3");
        }

    }

    @Override
    public void OnWholeItemClick(View view) {
        switch (view.getId()) {
            case R.id.itv_type://租赁类型
                showClassTypePop();
                break;
            case R.id.address:
                getLocationLL2();
                break;
            case R.id.time_course://使用时间(进场时间)
                showCourseTimePop();
                break;
            case R.id.time_deadline://报价截止时间
                if (TextUtils.isEmpty(binding.timeCourse.getContent())) {
                    MToast.showToast(getActivity(), "请选择使用时间");
                    return;
                }
                if (null != limitTimeDatas && limitTimeDatas.size() > 0) {
                    showLimitTimePop();
                }
                break;
            case R.id.payment_method://付款方式选择
                showPaymentMethodPop();
                break;
            case R.id.itv_floorStructure://楼层结果
                showFloorPop();
                break;
            default:
                break;

        }
    }

    //付款方式选择
    private void showPaymentMethodPop() {
        OptionsPickerView businessOption = new OptionsPickerBuilder(getActivity(), (options1, options2, options3, v) -> {
            String content = allpayway.get(options1).getName();
            viewModel.entity.setRentalPayMethod(content);
            binding.paymentMethod.setContent(content);
        }).build();
        businessOption.setPicker(allpayway);
        businessOption.setSelectOptions(0);
        businessOption.show();
    }

    // 楼层结构选择对话框
    private void showFloorPop() {
        ArrayList<PickSelectEntity> foolList = new ArrayList<>();
        foolList.add(new PickSelectEntity("1", "单层"));
        foolList.add(new PickSelectEntity("2", "多层"));
        int index = 0;
        if ("多层".equals(binding.itvFloorStructure.getContent())) {
            index = 1;
        }
        OptionsPickerView businessOption = new OptionsPickerBuilder(getActivity(), (options1, options2, options3, v) -> {
            String content = foolList.get(options1).getProjectscale();
            binding.itvFloorStructure.setContent(content);
            viewModel.entity.setFloorStructure(content);
        }).build();
        businessOption.setPicker(foolList);
        businessOption.setSelectOptions(index);
        businessOption.show();
    }

    //进场时间
    private void showCourseTimePop() {
        Calendar dayCalendar = Calendar.getInstance();
        dayCalendar.setTime(new Date());
        dayCalendar.add(Calendar.DAY_OF_MONTH, 1);

        TimePickerView timePicker = new TimePickerBuilder(getActivity(), (date, v) -> {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String format = sdf.format(date);
            try {
                binding.timeCourse.setContent(format);
                viewModel.entity.setUseAndEnterTime(DateUtils.dateTo13Timestamp(format + " 23:59:59") + "");
                selectedDate2.setTime(date);
                binding.timeDeadline.setContent("");//清空报价截止时间
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择时间")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .setRangDate(dayCalendar, null)
                .build();
        timePicker.show();
        timePicker.setDate(selectedDate2);
    }

    //报价截止时间
    private void showLimitTimePop() {
        TimePickerView timePicker = new TimePickerBuilder(getActivity(), (date, v) -> {
            try {
                @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String format = sdf.format(date);
                if (checkDate(format, binding.timeCourse.getContent())) {
                    return;
                }
                viewModel.entity.setEndTime(DateUtils.dateTo13Timestamp3(format + " 23:59:59") + "");
                binding.timeDeadline.setContent(format);
                selectedDate.setTime(date);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择时间")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .setRangDate(Calendar.getInstance(), null)
                .build();
        timePicker.show();
        timePicker.setDate(selectedDate);
    }

    //日期比较
    private boolean checkDate(String startTime, String endTime) {
        try {
            if (DateUtils.dateTo13Timestamp(endTime) < DateUtils.dateTo13Timestamp(startTime) || startTime.equals(endTime)) {
                MToast.showToast(getActivity(), "请选择小于使用时间的日期");
                return true;
            }
        } catch (Exception e) {
        }
        return false;
    }


    //返回省市区数据加载数据
    public void initAddressData(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        addressEntityList = data;
        initJsonData();
    }

    //组装省市区数据信息
    private void initJsonData() {
        for (int i = 0; i < addressEntityList.size(); i++) {
            ArrayList areaList = new ArrayList<>();
            opt2.add(addressEntityList.get(i).getChildren());
            for (int j = 0; j < addressEntityList.get(i).getChildren().size(); j++) {
                List<AddressEntity> cityAreaList = new ArrayList<>();
                List<AddressEntity> children = addressEntityList.get(i).getChildren().get(j).getChildren();
                if (children == null || children.size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(children);
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }
    }

    //发布数据
    private boolean checkInput() {
        if (!TextUtils.isEmpty(binding.itemTvPhone.getContent())) {
            if (!CheckUtils.isPhoneNumberValid(binding.itemTvPhone.getContent().trim())) {
                MToast.showToast(getActivity(), "请填写正确的联系电话");
                return false;
            }
        }

        if (TextUtils.isEmpty(binding.itvType.getContent())) {
            MToast.showToast(getActivity(), "请选择房产分类");
            return false;
        }


        viewModel.entity.setRentalDuration(binding.includeTime.leaseTime.getText().toString().trim());

        viewModel.entity.setReatalAreaUnit("㎡");
        viewModel.entity.setRentalUnit("㎡");
        viewModel.entity.setStoredDetail(binding.houseCargoInfo.getEditContent());

        if (TextUtils.isEmpty(binding.address.getContent())) {
            MToast.showToast(getActivity(), "请选择工作地");
            return false;
        }

        if (binding.inLeasePrice.rbPrice.isChecked()) {
            viewModel.entity.setRentalPrice("-1");
            viewModel.entity.setRentalSelectPrice("");
        } else {
            String price = binding.inLeasePrice.leasePrice.getText().toString().trim();
            if (!TextUtils.isEmpty(price)) {
                if (Double.parseDouble(price) <= 0) {
                    MToast.showToast(getActivity(), "请填写大于0的期望租金");
                    return false;
                }
            }
            viewModel.entity.setRentalPrice(price);
        }

        if (!TextUtils.isEmpty(binding.timeDeadline.getContent()) && !TextUtils.isEmpty(binding.timeCourse.getContent())) {
            if (checkDate(binding.timeDeadline.getContent(), binding.timeCourse.getContent())) {
                return false;
            }
        }

        //设置标题参数
        if (!TextUtils.isEmpty(binding.include.itemTvTitleEdit.getEditContent())) {
            viewModel.entity.setRentalTitle(binding.include.itemTvTitleEdit.getEditContent());
        } else {
            MToast.showToast(getActivity(), "请填写业务名称");
            return false;
        }


        viewModel.entity.setCategoryType("3");
        viewModel.entity.setContactPerson(binding.leaseUsername.getContent());
        viewModel.entity.setContactPhone(binding.itemTvPhone.getContent());
        viewModel.entity.setRemark(binding.leaseExpand.getEditContent());
        viewModel.entity.setRentalArea(binding.houseArea.getText().toString());
        return true;
    }



    //    机械、设备、车辆、房产分类
    private void showClassTypePop() {
        if (classDatas == null || classDatas.size() == 0) return;
        OptionsPickerView businessOption = new OptionsPickerBuilder(getActivity(), (options1, options2, options3, v) -> {
            String className = classDatas.get(options1).getProjectscale();
            if (typeDatas.size() == 0 || null == typeDatas.get(options1) || typeDatas.get(options1).size() == 0 || typeDatas.get(options1).get(options2) == null) {
                binding.itvType.setContent(className);
                viewModel.entity.setCategoryParentId(classDatas.get(options1).getNo());
            } else {
                String typeName = typeDatas.get(options1).get(options2).getProjectscale();
                binding.itvType.setContent(className + "/" + typeName);
                viewModel.entity.setCategoryParentId(classDatas.get(options1).getNo());
                viewModel.entity.setCategoryChildId(typeDatas.get(options1).get(options2).getNo());
                secondCategoryName = typeName;
            }
            setDefaultTitle();
        }).build();
        businessOption.setPicker(classDatas, typeDatas);
        businessOption.setSelectOptions(0, 0);
        businessOption.show();
    }


    //类型集合
    public void showTypeView(List<AskLeaseItemEntity<List<AskLeaseItemEntity<List<AskLeaseItemEntity>>>>> data) {
        for (AskLeaseItemEntity<List<AskLeaseItemEntity>> l : data.get(3).getChildren()) {
            PickSelectEntity entity = new PickSelectEntity();
            entity.setNo(l.getNo());
            entity.setProjectscale(l.getName());
            classDatas.add(entity);
            List<PickSelectEntity> childList = new ArrayList<>();
            for (AskLeaseItemEntity ll : l.getChildren()) {
                PickSelectEntity child = new PickSelectEntity();
                child.setNo(ll.getNo());
                child.setProjectscale(ll.getName());
                childList.add(child);
            }
            typeDatas.add(childList);
        }
    }

    // 付款方式
    public void getAllPayWay(List<DictEntity3> data) {
        this.allpayway = data;
    }

    public void getLocationLL2() {
        Intent intent = new Intent();
        intent.setClass(getActivity(), SelectAddressActivity.class);
        intent.putExtra(SelectAddressActivity.TITLE, "工作地");
        intent.putExtra(SelectAddressActivity.HINT, "请输入地址");
        intent.putExtra(SelectAddressActivity.SAVE_TEXT, "确定");
        if (!TextUtils.isEmpty(lat) && !TextUtils.isEmpty(lon)) {
            intent.putExtra(SelectAddressActivity.LATITUDE, Double.parseDouble(lat));
            intent.putExtra(SelectAddressActivity.LONGTITUDE, Double.parseDouble(lon));
        }
        startActivityForResult(intent, 255);
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 255 && data != null) {
                lat = data.getDoubleExtra(SelectAddressActivity.LATITUDE, 0) + "";
                lon = data.getDoubleExtra(SelectAddressActivity.LONGTITUDE, 0) + "";
                String address = data.getStringExtra(SelectAddressActivity.CURRENT_POSITION);
                PublishLeaseDataEntity.RentAddress rentAddress = viewModel.entity.getRentAddress();
                rentAddress.setLatitude(lat);
                rentAddress.setLongitude(lon);
                rentAddress.setTaskaddr(address);
                viewModel.entity.setRentAddress(rentAddress);
                binding.address.setContent(address);
            }
        }
    }

    //动态设置设置默认标题
    private void setDefaultTitle() {
        if (!TextUtils.isEmpty(binding.houseArea.getText())) {
            binding.include.tvTitleDefault.setText("求租" + binding.houseArea.getText().toString() + "㎡" + secondCategoryName);
        } else {
            binding.include.tvTitleDefault.setText("求租" + secondCategoryName);
        }
        binding.include.rlLeaseTitle.setVisibility(View.VISIBLE);
        binding.v.setVisibility(View.GONE);
    }

    /**
     * 编辑回显 使用
     *
     * @param detailEditEntity
     */
    public void showEdit(PublishLeaseDataEntity detailEditEntity) {
        viewModel.entity = detailEditEntity;

        binding.itvType.setContent(detailEditEntity.getCategoryParentName() + "/" + detailEditEntity.getCategoryChildName());
        binding.paymentMethod.setContent(detailEditEntity.getRentalPayMethod());
        viewModel.entity.setReatalAreaUnit("㎡");
        viewModel.entity.setRentalUnit("㎡");
        binding.houseArea.setText(detailEditEntity.getRentalArea());
        if (!TextUtils.isEmpty(detailEditEntity.getStoredDetail())) {
            binding.houseCargoInfo.setEditContent(detailEditEntity.getStoredDetail() + "");//存放物品明细
        } else {
            binding.houseCargoInfo.setEditContent("");//存放物品明细
        }
        if (!TextUtils.isEmpty(viewModel.entity.getFloorStructure())) {
            binding.itvFloorStructure.setContent(viewModel.entity.getFloorStructure());
        }
        //租赁时长
        binding.includeTime.leaseTime.setText(detailEditEntity.getRentalDuration());
        viewModel.entity.setRentalDuration(detailEditEntity.getRentalDuration());
        if(!TextUtils.isEmpty(detailEditEntity.getRentalDurationUnit())){
            binding.includeTime.tvTimeUnit.setText(detailEditEntity.getRentalDurationUnit());
            binding.inLeasePrice.tvPriceUnit.setText("元/" + detailEditEntity.getRentalDurationUnit());
        }
        try {
            if (Double.parseDouble(detailEditEntity.getRentalPrice()) >= 0) {
                binding.inLeasePrice.rbPrice.setButtonDrawable(R.mipmap.lease_pub_unselect);
                binding.inLeasePrice.rbPrice.setChecked(false);
                viewModel.entity.setRentalPrice(detailEditEntity.getRentalPrice());
                binding.inLeasePrice.layoutPrice.setVisibility(View.VISIBLE);
                binding.inLeasePrice.rbPrice.setText("面议");
                binding.inLeasePrice.leasePrice.setText(detailEditEntity.getRentalPrice());
                binding.inLeasePrice.tvPriceUnit.setText("元/" + detailEditEntity.getRentalDurationUnit());

            } else {
                binding.inLeasePrice.rbPrice.setChecked(true);
                viewModel.entity.setRentalPrice("-1");
                binding.inLeasePrice.rbPrice.setButtonDrawable(R.mipmap.lease_pub_select);
                binding.inLeasePrice.layoutPrice.setVisibility(View.GONE);
                binding.inLeasePrice.rbPrice.setText("您已选择面议，再次点击退出面议");
            }
        }catch (Exception e){
//            binding.inLeasePrice.rbPrice.setChecked(true);
//            viewModel.entity.setRentalPrice("-1");
//            binding.inLeasePrice.rbPrice.setButtonDrawable(R.mipmap.lease_pub_select);
//            binding.inLeasePrice.layoutPrice.setVisibility(View.GONE);
//            binding.inLeasePrice.rbPrice.setText("您已选择面议，再次点击退出面议");
        }

        if (!TextUtils.isEmpty(detailEditEntity.getEndTime())) {
            binding.timeDeadline.setContent(DateUtils.stampToDay(detailEditEntity.getEndTime()));
        }
        if(!TextUtils.isEmpty(detailEditEntity.getUseAndEnterTime())){
            binding.timeCourse.setContent(DateUtils.stampToDay(detailEditEntity.getUseAndEnterTime()));
        }
        binding.timeCourse.setContent(detailEditEntity.getUseAndEnterTime());
        binding.paymentMethod.setContent(detailEditEntity.getRentalPayMethod());
        binding.include.itemTvTitleEdit.setEditContent(detailEditEntity.getRentalTitle());
        binding.leaseUsername.setContent(detailEditEntity.getContactPerson());

        binding.address.setContent(detailEditEntity.getRentAddress().getTaskaddr());
        binding.itemTvPhone.setContent(detailEditEntity.getContactPhone());
        binding.leaseExpand.setEditContent(detailEditEntity.getRemark());
    }

    public static void hideKeyboard(View view) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    /**
     * 隐藏软键盘
     */
    private void setSoftWareHide() {
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(getActivity().getWindow().getDecorView().getWindowToken(), 0);
        }
    }

    /**
     * 设置沉浸状态栏下的title
     *
     * @param isImplement
     */
    protected void setTileImmerse(boolean isImplement) {
        if (isImplement) {
            TitleImmerse.assistActivity(getActivity().findViewById(android.R.id.content));

        }
    }

    /**
     * 租赁时长
     */
    private void showLeaseTime() {
        leaseTimeOpv = new OptionsPickerBuilder(getActivity(), (options1, options2, options3, v) -> {
            String content = leaseTimeDatas.get(options1).getProjectscale();
            String no = leaseTimeDatas.get(options1).getNo();
            binding.includeTime.tvTimeUnit.setText(content);
            binding.inLeasePrice.tvPriceUnit.setText("元/" + content);
            viewModel.entity.setRentalDurationUnit(content);
            viewModel.entity.setRentalDurationUnitNo(no);
        }).build();
        leaseTimeOpv.setPicker(leaseTimeDatas);
        leaseTimeOpv.setSelectOptions(0);
        if (leaseTimeDatas.size() > 0) {
            String unit = leaseTimeDatas.get(0).getProjectscale();
            viewModel.entity.setRentalDurationUnit(unit);
            viewModel.entity.setRentalDurationUnitNo(leaseTimeDatas.get(0).getNo());
            binding.includeTime.tvTimeUnit.setText(unit);
            binding.inLeasePrice.tvPriceUnit.setText("元/" + unit);
        }
    }


}
